//
//  ViewController.m
//  KVOTest
//
//  Created by muxue on 2019/4/22.
//  Copyright © 2019 暮雪. All rights reserved.
//

#import "ViewController.h"
#import "MXKVOTest.h"

@interface ViewController ()
@property (nonatomic, strong) MXKVOTest *test;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    MXKVOTest *test = [[MXKVOTest alloc] init];
    self.test = test;
    NSLog(@"after-->%s", object_getClassName(test));
    [test addObserver:self forKeyPath:@"name" options:NSKeyValueObservingOptionNew context:nil];
    NSLog(@"before-->%s", object_getClassName(test));
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self.test willChangeValueForKey:@"name"];
//    self.test.name = @"aaa";
    [self.test  didChangeValueForKey:@"name"];
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
    NSLog(@"___________________>%@------------------------>%@", keyPath, change[NSKeyValueChangeNewKey]);
}
@end
